package com.itheima.ThreadPrac;

public class mythread1 extends Thread{
     static  int ticket=1000;
    @Override
    public void run() {
       while (true)
       {
           synchronized (Thread.class)
           {
               if(ticket==0)
                   break;
               else
               {
                   try {
                       Thread.sleep(300);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   ticket--;
                   //票还没有买完，可以继续卖票
                   System.out.println(getName()+"卖票成功，现在还剩下"+ticket+"张票");

               }
           }
       }
    }
}
